//
//  DAInputBookLostReasonView.m
//  DAKnowledge
//
//  Created by DreamArts on 16/5/31.
//  Copyright © 2016年 lidongyang. All rights reserved.
//

#import "DAInputBookLostReasonView.h"
#import "Masonry.h"
#import "Utility.h"
#import "DAHeader.h"

@implementation DAInputBookLostReasonView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self confignView];
    }
    return self;
}

- (void)confignView {
    // 用户头像
    self.userImageView = [[UIImageView alloc]init];
    self.userImageView.layer.cornerRadius = 15;
    self.userImageView.clipsToBounds = YES;
    [self addSubview:self.userImageView];
    // 输入框
    self.textField = [[UITextField alloc]init];
    self.textField.backgroundColor = [UIColor colorWithHexString:timeLineColor];
    self.textField.layer.cornerRadius = 5;
    self.textField.delegate = self;
    NSString *lostReason = NSLocalizedString(@"inputLostReason", nil);
    self.textField.placeholder = lostReason;
    [self.textField setValue:[UIFont systemFontOfSize:14] forKeyPath:@"_placeholderLabel.font"];
    [self addSubview:self.textField];
    [self.textField addTarget:self action:@selector(textFieldDidEndEditing:) forControlEvents:UIControlEventEditingChanged];
    // 发送按钮
    self.postButton = [UIButton buttonWithType:UIButtonTypeCustom];
    NSString *sendMessage = NSLocalizedString(@"sendMessage", nil);
    [self.postButton setTitle:sendMessage forState:UIControlStateNormal];
    [self.postButton setTitleColor:[UIColor colorWithHexString:borrowTimeColor] forState:UIControlStateNormal];
    self.postButton.userInteractionEnabled = NO;
    [self.postButton addTarget:self action:@selector(clickPostButton) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.postButton];
    
}
- (void)layoutSubviews{
    
    [self.userImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(5);
        make.left.mas_equalTo(8);
        make.width.height.mas_equalTo(30);
    }];
    [self.postButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(8);
        make.right.mas_equalTo(-8);
        make.width.mas_equalTo(50);
        make.bottom.mas_equalTo(-8);
    }];
    
    [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(5);
        make.bottom.mas_equalTo(-5);
        make.left.mas_equalTo(self.userImageView.mas_right).offset(8);
        make.right.mas_equalTo(self.postButton.mas_left).offset(-8);
    }];
    
}

- (void)textFieldDidEndEditing:(UITextField *)textField{
    if (textField.text.length > 0) {
        [self.postButton setTitleColor:[UIColor supportGreenColor] forState:UIControlStateNormal];
        self.postButton.userInteractionEnabled = YES;
    }else{
        [self.postButton setTitleColor:[UIColor colorWithHexString:borrowTimeColor] forState:UIControlStateNormal];
        self.postButton.userInteractionEnabled = NO;
    }

}

- (void)clickPostButton{
    [self.delegate postBookLostMessage];
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
